package com.sbio.udiapp.util;

import com.blankj.utilcode.util.StringUtils;

public class StringUtil {
    public static String prettyUdi(String pbNo, String stockNo, Integer qty) {
        if (!CommonUtil.isPbNo(pbNo)) {
            return pbNo;
        }
//        if (pbNo.length() != 56) {
//            return pbNo;
//        }
        StringBuilder sb = new StringBuilder(pbNo);
        if (CommonUtil.isUdi(pbNo)) {
            int[] positions = {16, 25, 34, 47};
            for (int position : positions) {
                sb.insert(position, "\n");
            }
        }

        if (!StringUtils.isEmpty(stockNo)) {
            sb.append("\n仓库编码：" + stockNo);
        }
        if (qty != null && qty != 0) {
            sb.append("\n数量：" + qty);
        }
        //箱码数据
        String data = sb.toString();
        return data;
    }


    /**
     * 还原美化后的udi
     */
    public static String restorePrettyUdi(String udi, String stockNo) {
        if (!StringUtils.isEmpty(stockNo)) {
            udi = udi.replace("\n仓库编码：" + stockNo, "");
        }
        return udi.replace("\n", "");
    }
}
